package com.qf.smartplatform.dto;/*
*王浩政 
*whz
2022/9/7
17:48
*小米商城
*/

import com.qf.smartplatform.constans.ResultCode;
import com.qf.smartplatform.pojo.CheckNull;
import com.qf.smartplatform.valigroup.Insert;
import com.qf.smartplatform.valigroup.Select;
import com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureECDSA;
import lombok.Data;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Data
@ToString
public class UserDto implements CheckNull {
    //group指的是当前校验的时候指定的group属于当前groups中的一个的时候就进行校验
   // @NotEmpty(message = "用户名是不可以是空白的，请您检查一下的哦",groups = {Insert.class, Select.class})
    @Length(min = 6, max = 10 ,message = "{\"code\": "+ ResultCode.PARAM_CONTENT_PARTTEN_ERROR +",\"msg\": \"密码长度6-10\"}", groups ={Insert.class, Select.class})
    private String username;
//    @Min(value = 6,message = "您的长度需要在6-10之间哦")//最小的长度是6
//    @Max(value = 10,message = "您的长度需要在6-10之间哦")//最大的长度是10
      @Length(min = 6,max=10)
    private String password;
    //private ResultCode resultCode;
    //private  ResultCode resultCode;
    //    @NotEmpty(message = "你必须传递响应的昵称",groups = Insert.class)
//@NotEmpty(message = "{\"code\": "+ ResultCode.PARAM_CONTENT_EMPTY +",\"msg\": \"必须传递昵称\"}", groups = Insert.class)
 //   @NotEmpty(message = "{\"code\": "+ResultCode.PARAM_CONTENT_EMPTY +",\"msg\":\"必须传递呢称\"}",groups = Insert.class)
   // @NotEmpty(message = "{\"code\":0,\"msg\":\"必须要传递昵称哦\"}")
//@NotEmpty(message = "{\"code\":"+ ResultCode.PARAM_CONTENT_EMPTY +",\"msg\":\"必须要传递昵称哦\"}")
//    private String name;
    @NotEmpty(message = "{\"code\": "+ ResultCode.PARAM_CONTENT_EMPTY +",\"msg\": \"必须传递昵称\"}", groups = Insert.class)
    private String name;

   // @Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$",groups = Insert.class)
   @Pattern(regexp = "^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$", groups = Insert.class,message = "{\"code\": "+ ResultCode.PARAM_CONTENT_PARTTEN_ERROR +",\"msg\": \"手机号错误\"}")
    private String phone;
    //@Pattern(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$",groups = Insert.class)
    @Pattern(regexp = "^\\w+@[\\da-z\\.-]+\\.([a-z]{2,6}|[\\u2E80-\\u9FFF]{2,3})$", groups = Insert.class,message = "{\"code\": "+ ResultCode.PARAM_CONTENT_PARTTEN_ERROR +",\"msg\": \"邮箱错误\"}")
    private String email;
    //@NotEmpty(groups = Insert.class)
    @NotNull(groups = Insert.class,message = "{\"code\": "+ ResultCode.PARAM_CONTENT_EMPTY +",\"msg\": \"性别未传递\"}")
    private Long sex;

    @Override
    public boolean isEmpty() {
        return !StringUtils.hasText(username)
                || !StringUtils.hasText(password)
                || !StringUtils.hasText(name)
                || !StringUtils.hasText(phone)
                || !StringUtils.hasText(email)
                || ObjectUtils.isEmpty(sex)
                || (sex != 0 & sex != 1);
    }


}
